<?php

/*
 * This will be the Edit Route page. 
 * 
 * Created by: Peter Agno Jr.
 * Date created: December 14, 2011
 */
    
    include("siteTop.php"); 
    include('includes/siteConfig.php'); 

    // connect to database
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    // Get the data from post
    $routeId = $_POST['routeId'];
    // Variables for track circles
    $circleVersion = "5";
    $lineWidth = "60";
    $lineHeight = "23";
    $circleWidth = "23";
    $circleHeight = "23";
    
    // Get $routeId details
    $query =
        "
            SELECT *
            FROM DocumentRoute
            WHERE routeId = '$routeId'
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
    $row = mysql_fetch_array($result);
    $routeName = $row['routeName'];
    $documentSetupId = $row['documentSetupId'];
    
    // Start - Get the subroute name depending on the passed $theSubRouteId
    function getSubRouteName($theSubRouteId) {
        $query =
            "
                SELECT subRouteName
                FROM SubRoute
                WHERE subRouteId = '$theSubRouteId'
            ";
        
        $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
        $row = mysql_fetch_array($result);
        $temp = $row['subRouteName'];
        return $temp;
    } // End - Get the subroute name depending on the passed $theSubRouteId
    
    // Start - Add the sub route drop down
    function addSubRouteDrpDwnPhp($rowNum, $theSubRouteId, $theSubRouteName) {
        echo "<select id='subRouteDrpDwn_".$rowNum."' class='subRouteDrpDwn' ";
        
        if ( $theSubRouteId == "REJECTTRAC" || $theSubRouteId == "CANCELTRAC" ) {
            echo "style='display:none;' ";
        }
        
        echo ">";
        
        echo "<option value='".$theSubRouteId."'>".$theSubRouteName."</option>";
        
        // Add other routes
        if ( $theSubRouteId != "REJECTTRAC" && $theSubRouteId != "CANCELTRAC" ) {
            echo "<option value='selectSubRoute'>Select Sub Route</option>";
            
            $query =
                "
                    SELECT *
                    FROM SubRoute
                    WHERE subRouteId != '$theSubRouteId' AND subRouteId != 'REJECTTRAC' AND subRouteId != 'CANCELTRAC'
                ";
            $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
            
            while ( $row = mysql_fetch_array($result) ) {
                echo "<option value='".$row['subRouteId']."'>".$row['subRouteName']."</option>";
            }
            
            echo "<option value='newSubRoute'>Create New Sub Route</option>";
        }

        echo "</select>";
        
        // Add the subRouteIdIptBx and subRouteNameIptBx
        echo "<table id='subRouteTbleIptBx_".$rowNum."' border='0'; style='display:none; margin-bottom: 5px; margin-top: 5px; border-top: 0px;'>";
        echo "<tr>";
        echo "<td>ID : </td>";
        echo "<td><input id='subRouteIdIptBx_".$rowNum."' name='subRouteIdIptBx' value=''/></td>";
        echo "</tr>";

        echo "<tr>";
        echo "<td>Name : </td>";
        echo "<td><input id='subRouteNameIptBx_".$rowNum."' name='subRouteNameIptBx' value=''/></td>";
        echo "</tr>";
        echo "</table>";
    } // End - Add the sub route drop down
    
    // Start - Get the total step number of the subroute
    function getTotalStepNum($theSubRoute, $routeId) {
        // Prepare query
        if ( $theSubRoute == "NULL" ) {
            $query =
            "
                SELECT *
                FROM RouteStep
                WHERE subRouteId IS NULL AND routeId = '$routeId'
            ";
        }
        else {
            $query =
            "
                SELECT *
                FROM RouteStep
                WHERE subRouteId = '$theSubRoute' AND routeId = '$routeId'
            ";
        }

        $result = mysql_query($query) or die ('Error in query: $result. ' . mysql_error());
        $totalStepNum = mysql_num_rows($result);
        
        return $totalStepNum;
    } // End - Get the total step number of the subroute
    
    // Start - Add a row in the stepInfoTable
    function addStepInfoTable($rowNum, $stepNum, $RSStepId, $RSStepNum, $RSRole, $RSCancelFlag, $RSUserActivity, $RSCategory) {
        echo "<tr id='stepInfo_".$rowNum."_".$stepNum."' class='stepInfo_".$rowNum." stepInfoRows' style='display:none;'>";
        echo "<td>";
        echo "<table border='0' style='border-top-style:none;'>";

        echo "<tr>"; // Start - tr first row

        // *************** Step Number ***************
        echo "<td valign='top'>"; // Start td
        echo "<table border='0' style='border-top-style:none;'>";
        echo "<tr>";
        echo "<td>Step Number : </td>";
        echo "<td><span id='rowStepNum_".$rowNum."_".$stepNum."'>".$RSStepNum."</span></td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>Sub Route Name : </td>";
        echo "<td><span id='rowSubRouteName_".$rowNum."_".$stepNum."'></span></td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>Category : </td>";
        echo "<td><input type='text' id='category_".$rowNum."_".$stepNum."' class='category_".$rowNum." category' value='".$RSCategory."' /></td>";
        echo "</tr>";
        echo "</table>";
        echo "</td>"; // End td

        // *************** Role and Transaction cancelled ***************
        echo "<td valign='top'>"; // Start td
        echo "<table border='0' style='border-top-style:none;'>";
        echo "<tr>";
        echo "<td>Recipient Role : </td>";
        echo "<td>";
        echo "<select id='role_".$rowNum."_".$stepNum."' class='role_".$rowNum." recipientRoles'>";
        
        // Arrange showing of roles
        if ( $RSRole == "1" ) {
            echo "<option value='1'>Sender</option>";
            echo "<option value='2'>Approving Authority</option>";
            echo "<option value='3'>Archiver</option>";
        }
        else if ( $RSRole == "2" ) {
            echo "<option value='2'>Approving Authority</option>";
            echo "<option value='3'>Archiver</option>";
            echo "<option value='1'>Sender</option>";
        }
        else {
            echo "<option value='3'>Archiver</option>";
            echo "<option value='1'>Sender</option>";
            echo "<option value='2'>Approving Authority</option>";
        }
        
        echo "</select>";
        echo "</td>";
        echo "</tr>";

        echo "<tr>";
        echo "<td>Transaction Can Be Cancelled : </td>";
        echo "<td>";
        echo "<select id='cancel_".$rowNum."_".$stepNum."' class='cancel_".$rowNum." canBeCancelled'>";
        
        // Arrange showing of cancel
        if ( $RSCancelFlag == "1" ) {
            echo "<option value='Yes'>Yes</option>";
            echo "<option value='No'>No</option>";
        }
        else {
            echo "<option value='No'>No</option>";
            echo "<option value='Yes'>Yes</option>";
        }

        echo "</select>";
        echo "</td>";
        echo "</tr>";
                
        echo "<tr>";
        echo "<td valign='top'>User Activity : </td>";
        echo "<td><textarea rows='4' cols='30' id='userAct_".$rowNum."_".$stepNum."' class='userAct_".$rowNum." userActivity'>".$RSUserActivity."</textarea></td>";
        echo "</tr>";
        echo "</table>";
        echo "</td>"; // End td

        echo "</tr>";  // End - tr first row

        echo "<tr>"; // Start - tr second row

        // *************** Required Attachments ***************
        echo "<td valign='top'>"; // Start td
        echo "<span class='screenlet' style='text-align:center;padding-left : 0; padding-right : 0; padding-top : 0;width:100%' >Required Attachments</span>";
        echo "<table id='reqAttachTable_".$rowNum."_".$stepNum."' border='1' style='padding-left : 0; padding-right : 0; padding-top : 0; width:100%'>";

        // Required Attachment header
        echo "<tr><th>Attachment Name</th><th>Action</th></tr>";

        addAttachmentRowPhp($RSStepId, $rowNum, $stepNum); // Add the created required attachments       
        $tempVar = countReqAttachments($RSStepId); // Count the recipients for this step
        
        if ( $tempVar == 0 ) {
            $tempVar = 1;
            echo "<tr id='noReqTr_".$rowNum."_".$stepNum."'><td colspan='2'>No Required Attachment</td></tr>";
        }
        else {
            echo "<tr id='noReqTr_".$rowNum."_".$stepNum."' style='display:none;'><td colspan='2'>No Required Attachment</td></tr>";
        }

        // Row for Add Attachment Button
        echo "<tr id='addReqAttachBtnRw_".$rowNum."_".$stepNum."'>";
        echo "<td> &nbsp <input type='hidden' id='addReqAttachNumRow_".$rowNum."_".$stepNum."' value='".$tempVar."' /></td>"; // This variable will be used in incrementing the the rows of the reqAttachment
        echo "<td style='text-align:center;'><input type='Submit' id='addReqAttachBtn_".$rowNum."_".$stepNum."' value='Add' class='siteGreenButton addReqAttachBtn' /></td>";
        echo "</tr>";
        echo "</table>";
        echo "</td>"; // End td

        // *************** Recipient ***************
        echo "<td valign='top'>"; // Start td
        echo "<span class='screenlet' style='text-align:center;padding-left : 0; padding-right : 0; padding-top : 0;width:100%' >Recipients</span>";
        echo "<table id='recipientTable_".$rowNum."_".$stepNum."' border='1' style='padding-left : 0; padding-right : 0; padding-top : 0; width:100%'>";

        // Required Recipient header
        echo "<tr><th>Position</th><th>Action</th></tr>";

        addRecipientRowPhp($RSStepId, $rowNum, $stepNum); // Add the created recipients       
        $tempVar = countStepRecipients($RSStepId); // Count the recipients for this step

        // Row for Add Recipient Button
        echo "<tr id='addRecipientBtnRw_".$rowNum."_".$stepNum."'>";
        echo "<td> &nbsp <input type='hidden' id='addRecipientNumRow_".$rowNum."_".$stepNum."' value='".$tempVar."' /></td>"; // This variable will be used in incrementing the the rows of the addRecipientRow
        echo "<td style='text-align:center;'><input type='Submit' id='addRecipientBtn_".$rowNum."_".$stepNum."' value='Add' class='siteGreenButton addRecipientBtn' /></td>";
        echo "</tr>";
        echo "</table>";
        echo "</td>"; // End td

        echo "</tr>"; // End - tr second row


        // *************** Remove Step Info Row ***************
        echo "<tr>"; // Start - tr third row
        echo "<td style='text-align: right;' colspan='2'>"; // Start td
        echo "<input type='Submit' id='rmvStepInfoRow_".$rowNum."_".$stepNum."' value='Remove' class='siteGreenButton rmvStepInfoRow'>"; // Remove Step Info Row Button
        echo "</td>"; // End td
        echo "</tr>"; // Start - tr third row

        echo "</table>";
        echo "</td>";
        echo "</tr>";
    } // End - Add a row in the stepInfoTable
    
    // Start - count the recipients in that step
    function countStepRecipients($RSStepId) {
        $query =
            "
                SELECT *
                FROM RouteStep_Dept_Pos
                WHERE stepId = '$RSStepId'
            ";

        $result = mysql_query($query) or die ('Error in query: $result. ' . mysql_error());
        $totalCount = mysql_num_rows($result);
        
        return $totalCount;
    } // End - count the recipients in that step
    
    // Start - count the required attachments in that step
    function countReqAttachments($RSStepId) {
        $query =
            "
                SELECT *
                FROM RouteStep_Req_Attachment
                WHERE stepId = '$RSStepId'
            ";

        $result = mysql_query($query) or die ('Error in query: $result. ' . mysql_error());
        $totalCount = mysql_num_rows($result);
        
        return $totalCount;
    } // End - count the required attachments in that step
    
    // Start - Get the Positions, put inside tr, this will be appended later on to recipientTable
    function addRecipientRowPhp($RSStepId, $rowNum, $stepNum) {
        $addRecipientNumRow = 1;
        
        // Query the recipients for each step
        $query =
        "
            SELECT DP.deptPosId as deptPosId, D.departmentName as departmentName, P.positionName as positionName
            FROM RouteStep_Dept_Pos as RSDP, Department_Position as DP, Department as D, Position as P
            WHERE RSDP.stepId = '$RSStepId' AND RSDP.deptPosId = DP.deptPosId AND DP.departmentId = D.departmentId AND DP.positionId = P.positionId
            ORDER BY RSDP.stepId
        ";
        $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
        
        while ($row = mysql_fetch_array($result)) {
            echo "<tr id='recipientRow_".$rowNum."_".$stepNum."_".$addRecipientNumRow."'>";
            echo "<td>";
            echo "<select id='recipientRow_".$rowNum."_".$stepNum."' class='recipientRow_".$rowNum."_".$stepNum." recipientRow_".$rowNum." recipientRow'>";
            echo "<option value='".$row['deptPosId']."'>".$row['departmentName']." - ".$row['positionName']."</option>";
            
            // Start - Add the options which contains other deptPosId info
                $tempDeptPosId = $row['deptPosId'];
                $innerQuery =
                    "
                        -- Filter Department and Position
                        SELECT DP.deptPosId as deptPosId, D.departmentName as departmentName, P.positionName as positionName
                        FROM Department_Position as DP, Department as D, Position as P
                        WHERE DP.deptPosId != '$tempDeptPosId' AND DP.departmentId = D.departmentId AND DP.positionId = P.positionId
                        ORDER BY D.departmentName, P.positionName ASC
                    ";
                $innerResult = mysql_query($innerQuery) or die ('Error in query: $innerQuery. ' . mysql_error());

                while ($innerRow = mysql_fetch_array($innerResult)) {
                    echo "<option value='".$innerRow['deptPosId']."'>".$innerRow['departmentName']." - ".$innerRow['positionName']."</option>";
                }
            // End - Add the options which contains other deptPosId info
            
            echo "</select>";
            echo "</td>";
            // Prepare the delete button
            echo "<td style='text-align:center;'><img id='rmvRecipient_".$rowNum."_".$stepNum."_".$addRecipientNumRow."' class='rmvRecipient' src='images/ximage.png' height='20px' width='20px' style='cursor: pointer;'/></td>";
            echo "</tr>";
            
            $addRecipientNumRow++;
        }
    } // End - Get the Positions, put inside tr, this will be appended later on to recipientTable
    
    // Start - Get the required attachments, put inside tr, this will be appended later on to reqAttachTable
    function addAttachmentRowPhp($RSStepId, $rowNum, $stepNum) {
        $addReqAttachNumRow = 1;
        
        // Query the required attachments for each step
        $query =
        "
            SELECT DS.documentSetupId as documentSetupId, DS.documentName as documentName
            FROM RouteStep_Req_Attachment as RRA, DocumentSetup as DS
            WHERE RRA.stepId = '$RSStepId' AND RRA.documentSetupId = DS.documentSetupId
        ";
        $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
        
        while ($row = mysql_fetch_array($result)) {
            echo "<tr id='reqAttachRow_".$rowNum."_".$stepNum."_".$addReqAttachNumRow."'>";
            echo "<td>";
            echo "<select id='reqAttach_".$rowNum."_".$stepNum."' class='reqAttach_".$rowNum."_".$stepNum." reqAttach_".$rowNum." reqAttach'>";
            echo "<option value='".$row['documentSetupId']."'>".$row['documentName']."</option>";
            
            // Start - Add the options which contains other documentSetupId info
                $tempDocumentSetupId = $row['documentSetupId'];
                $innerQuery =
                    "
                        SELECT *
                        FROM DocumentSetup
                        WHERE documentSetupId != '$tempDocumentSetupId'
                        ORDER BY documentName ASC
                    ";
                $innerResult = mysql_query($innerQuery) or die ('Error in query: $innerQuery. ' . mysql_error());

                while ($innerRow = mysql_fetch_array($innerResult)) {
                    echo "<option value='".$innerRow['documentSetupId']."'>".$innerRow['documentName']."</option>";
                }
            // End - Add the options which contains other deptPosId info
            
            echo "</select>";
            echo "</td>";
            // Prepare the delete button
            echo "<td style='text-align:center;'><img id='rmvReqAttach_".$rowNum."_".$stepNum."_".$addReqAttachNumRow."' class='rmvReqAttach' src='images/ximage.png' height='20px' width='20px' style='cursor: pointer;'/></td>";
            echo "</tr>";
            
            $addReqAttachNumRow++;
        }
    } // End - Get the required attachments, put inside tr, this will be appended later on to reqAttachTable
?>

<!-- HEADER START -->
    <!--JAVASCRIPT SOURCES-->
    <script src="js/jquery-1.6.2.min.js"></script>
    
    <!--ACTUAL JS SCRIPTS AND JQUERIES-->
    <script type="text/javascript">
        jQuery(document).ready(function(){ 
            var subRouteNumRows = jQuery("#subRouteNumRows").val(), globalErrMsg = "", circleVersion = "5", lineWidth = "60", lineHeight = "23", circleWidth = "23", circleHeight = "23";
            
            // CHANGE FIRST THE CSS OF THE NAV BAR
            jQuery("#adminTools-nav").addClass("highlightMenuBar");
            jQuery("#routeSetup-nav").addClass("highlightMenuBar");
            
            // ************************************************************************************
            // Start - jQueries for Edit
            
            jQuery("#documentSetupId").val(jQuery("#updtDocStpId").val()); // Update the documentSetupId updtDocStpId
            
            // End - jQueries for Edit
            // ************************************************************************************
            
            // ************************************************************************************
            // Start - jQueries for Create
            
            // Start - Add a subroute row
            jQuery('#addSubRoute').live("click",function() {
                appndSubRRow = "";
                subRouteNumRows++;
                appndSubRRow += "<tr id='subRouteRow_"+subRouteNumRows+"' class='subRouteRow' >";
                
                // Sub route name
                appndSubRRow += "<td style='padding-top: 5px; padding-bottom: 5px;'>";
                appndSubRRow += "<select id='subRouteDrpDwn_"+subRouteNumRows+"' class='subRouteDrpDwn'>";
                tempSubR = addSubRouteDrpDwn();
                appndSubRRow += tempSubR;
                appndSubRRow += "</select>";
                
                // hidden table for input boxes of subroute name and id
                appndSubRRow += "<table id='subRouteTbleIptBx_"+subRouteNumRows+"' border='0'; style='display:none; margin-bottom: 5px; margin-top: 5px; border-top: 0px;'>";
                appndSubRRow += "<tr>";
                appndSubRRow += "<td>ID : </td>";
                appndSubRRow += "<td><input id='subRouteIdIptBx_"+subRouteNumRows+"' name='subRouteIdIptBx' value=''/></td>";
                appndSubRRow += "</tr>";
                
                appndSubRRow += "<tr>";
                appndSubRRow += "<td>Name : </td>";
                appndSubRRow += "<td><input id='subRouteNameIptBx_"+subRouteNumRows+"' name='subRouteNameIptBx' value=''/></td>";
                appndSubRRow += "</tr>";
                appndSubRRow += "</table>";
                
                appndSubRRow += "</td>";
                
                // sub route steps
                appndSubRRow += "<td id='subRouteSteps_"+subRouteNumRows+"'>";
                appndSubRRow += "<div class='scrollRouteOuterDiv' id='subRouteStepsOuterDiv_"+subRouteNumRows+"'><div class='scrollRouteInnerDiv' id='subRouteStepsInnerDiv_"+subRouteNumRows+"'>"; // For scroll of the route
                appndSubRRow += "<a href='javascript:void(0)'>";
                tempCircleId = "route_"+subRouteNumRows+"_circle_1";
                tempCircle = getNeededCircle(tempCircleId, subRouteNumRows, "single", "grn", "nothov", "sngle");
                appndSubRRow += tempCircle;
                appndSubRRow += "</a>";
                appndSubRRow += "<input type='hidden' id='subRouteStepNum_"+subRouteNumRows+"' class='subRouteStepNum' value='1' />";
                appndSubRRow += "</div></div>"; // End - For scroll of route
                appndSubRRow += "</td>";

                // action
                appndSubRRow += "<td>"; 
                appndSubRRow += "<input type='Submit' id='addStep_"+subRouteNumRows+"' class='siteGreenButton addStep' value='Add Step' /> &nbsp";
                appndSubRRow += "<img src='images/ximage.png' height='20px' width='20px' style='cursor: pointer;' id='rmvSubRouteRow_"+subRouteNumRows+"' class='rmvSubRouteRow'/>";
                appndSubRRow += "</td>";
                
                appndSubRRow += "</tr>"; // Close the row
                jQuery("#addSubRouteRow").before(appndSubRRow); // Append the row
                addStepInfoTable(subRouteNumRows, "1"); // Add a row in the stepInfoTable
            }); // End - Add a subroute row
            
            // Start - Show the subRouteTbleIptBx of the row, depending on the change subRouteDrpDwn
            jQuery('.subRouteDrpDwn').live("change",function() {
                buttonId = this.id;
                tempSubstr = buttonId.split('_');
                
                if ( jQuery("#subRouteDrpDwn_"+tempSubstr[1]).val() == "newSubRoute" ) {
                    jQuery("#subRouteTbleIptBx_"+tempSubstr[1]).show();
                    jQuery("#subRouteIdIptBx_"+tempSubstr[1]).focus();
                }
                else {
                    jQuery("#subRouteTbleIptBx_"+tempSubstr[1]).hide();
                }
            }); // End - Show the subRouteTbleIptBx of the row, depending on the change subRouteDrpDwn
            
            // Start - Remove a sub route row
            jQuery('.rmvSubRouteRow').live("click",function() {
                buttonId = this.id;
                tempSubstr = buttonId.split('_');
                tempName = getSubRouteName(tempSubstr[1]);
                
                var contEdit = confirm("Do you really want to delete " + tempName + " route?");
                
                if ( contEdit == true ) {
                    jQuery("#subRouteRow_"+tempSubstr[1]).remove();
                    jQuery(".stepInfo_"+tempSubstr[1]).remove();
                    jQuery(".stepInfoDiv").hide(); // hide the step information
                }
            }); // End - Remove a sub route row 
            
            // Start - Edit route
            jQuery("#editButton").live("click",function() {
                if ( jQuery("#routeName").val() == "" ) {
                    alert("Please input the Route Name.");
                }
                else if ( noSelectSubRoute() != true ) {
                   alert("Please select a Sub Route.");
                }
                else if ( validNewSubRoute() != true ) {
                   alert("Please input all information in creating a new sub route.");
                }
                else if ( noDupSRIdIptBx() != true ) {
                   alert("There should be no same Sub Route Id.");
                }
                else if ( noSameSubRoute() != true ) {
                   alert("There should be no same sub route.");
                }
                else if ( noSameReqAttach() != true ) {
                   alert(globalErrMsg);
                }
                else if ( noSameRecipient() != true ) {
                   alert(globalErrMsg);
                }
                else if ( noEmptyUsrAct() != true ) {
                    alert(globalErrMsg);
                }
                else if ( noEmptyCategory() != true ) {
                    alert(globalErrMsg);
                }
                else {
                    // Initialize variables
                    var subRouteIds="", newSubRouteNames="", subRouteSteps="", newSubRouteIds="", recipientRoles="", canBeCancelled="", reqAttach="", recipientRow="", userActivity="", category="";
                    
                    var contEdit = confirm("Do you really want to edit " + jQuery("#routeName").val() + " route?");
                    
                    if ( contEdit == true ) {
                        // Comment out
                        // This shows the prompt for please wait
                        jQuery("#plsWaitDiv").show();
                        jQuery("#otherBtnsDiv").hide();
                        // Add transparent box and content box
//                        jQuery(".body").prepend("<div class='theatreTransparent'> </div>");
//                        jQuery(".body").prepend("<div class='theatreContentBox' style='width: 78%; margin-left:11%; position: absolute;'> </div>");   
                        // Add theatreContent
//                        jQuery(".theatreContentBox").append("<div class='theatreContent' style='margin-right: 0%; margin-left: 3.5%;'></div>");
//                        jQuery(".theatreContent").append("<div class='remarksDiv'></div>");
//                        jQuery(".remarksDiv").append("<img src='images/others/loading_1.gif' height='15px' width='15px' /> ");
//                        jQuery(".remarksDiv").append("Please wait while the route is being edited.");
//                        window.scrollTo(0, 0);
                        
                        subRouteIds = getSubRouteIds();
                        newSubRouteIds = getNewSubRouteIds();
                        newSubRouteNames = getNewSubRouteNames();
                        subRouteSteps = getSubRouteSteps();
                        recipientRoles = getDrpDwnValues("recipientRoles");
                        canBeCancelled = getDrpDwnValues("canBeCancelled");
                        reqAttach = getDrpDwnValues("reqAttach");
                        recipientRow = getDrpDwnValues("recipientRow");
                        
                        // getDrpDwnValues() was supposed to be for dropdown fields
                        // This was also used for text boxes due to some changes that needs to be done.
                        // Like adding the userActivity and category.
                        userActivity = getDrpDwnValues("userActivity");
                        category = getDrpDwnValues("category");

                        // Start - Ajax for creating a route 
                        jQuery.ajax({
                            type : 'POST',
                            url : 'ajaxRequests/admRouteEditAjax.php',
                            dataType : 'json',
                            async : false,
                            data: {
                                routeId : jQuery("#theRouteId").val(),
                                routeName : jQuery("#routeName").val(),
                                documentSetupId : jQuery("#documentSetupId").val(),
                                subRouteIds : subRouteIds,
                                newSubRouteIds : newSubRouteIds,
                                newSubRouteNames : newSubRouteNames,
                                subRouteSteps : subRouteSteps,
                                recipientRoles : recipientRoles,
                                canBeCancelled : canBeCancelled,
                                reqAttach : reqAttach,
                                recipientRow : recipientRow,
                                userActivity : userActivity,
                                category : category
                            },
                            success : function(data){
                                if (data) {
                                    if ( data[0].flag == "success" ) {
                                        jQuery("#routeSuccessMessage").val(data[0].msg);
                                        jQuery("#routeStpMsgForm").submit();
                                    }
                                    else {
                                        alert(data[0].msg);
                                    }
                                }
                            },
                            error : function() {
                                alert("Error : Editing the route was not successful.");
                            }
                        }); // End - Ajax for editing a route
                        
                        // Comment out
                        // This shows the prompt for please wait
//                        jQuery(".theatreTransparent").remove();
//                        jQuery(".theatreContentBox").remove();
                        jQuery("#plsWaitDiv").hide();
                        jQuery("#otherBtnsDiv").show();
                    } // End if for confirmation box
                } // End else
            }); // End - Edit route
            
            // Start - Go back to admRouteSetup.php
            jQuery('#cancelButton').live("click",function() {
                window.location = 'admRouteSetup.php';
            }); // End - Go back to admRouteSetup.php 
            
            // Start - Add a circle in the subRouteSteps_n column
            jQuery('.addStep').live("click",function() {
                tempVar = this.id;
                tempSubstr = tempVar.split('_');
                
                // Increment the the subRouteStemNum
                jQuery("#subRouteStepNum_"+tempSubstr[1]).val(parseInt(jQuery("#subRouteStepNum_"+tempSubstr[1]).val()) + 1);
                
                // Now that we had prepared the append of line and circle,
                // we must update first the image of the circle before the one that will be appended.
                
                // Get the id of the first circle of that row
                countCircle = 0;
                jQuery(".routeCircle_"+tempSubstr[1]).each(function(index) {
                    firstCircleId = this.id;
                    countCircle++;
                });
                
                if ( countCircle != 0 ) {
                    // Don't add line if countCircle == 0
                    tempLineId = "route_"+tempSubstr[1]+"_line_"+jQuery("#subRouteStepNum_"+tempSubstr[1]).val();
                    tempLine = getLine(tempLineId, tempSubstr[1]);
                    
                    // Change now the  image of the circle before the one that will be appended
                    if ( countCircle == 1 ) {
                        jQuery("#"+firstCircleId).attr("src", "images/trackDoc/version"+circleVersion+"/first/grn_nothov_frst.png");
                    }
                    else {
                        jQuery("#"+firstCircleId).attr("src", "images/trackDoc/version"+circleVersion+"/center/grn_nothov_cntr.png");
                    }
                    
                    // Append line
                    // Don't add line if countCircle == 0
                    jQuery("#subRouteStepsInnerDiv_"+tempSubstr[1]).append(tempLine);
                    
                    // Prepare variables for the circle
                    folderName = "last";
                    theSuffix = "last";
                }
                else {
                    // Prepare variables for the circle
                    folderName = "single";
                    theSuffix = "sngle";
                }
                
                tempCircleId = "route_"+tempSubstr[1]+"_circle_"+jQuery("#subRouteStepNum_"+tempSubstr[1]).val();
                tempCircle = getNeededCircle(tempCircleId, tempSubstr[1], folderName, "grn", "nothov", theSuffix);
                
                // Append circle
                jQuery("#subRouteStepsInnerDiv_"+tempSubstr[1]).append(tempCircle);
                
                // Now that you have appended the line and circle,
                // adjust the scroll bar of that route.
                if ( countCircle >= 8 ) {
//                    tempWidth = parseInt(jQuery("#subRouteStepsInnerDiv_"+tempSubstr[1]).width()) + 50;
//                    alert(tempWidth);
//                    jQuery("#subRouteStepsInnerDiv_"+tempSubstr[1]).css("width", tempWidth);
//                    jQuery("#subRouteStepsOuterDiv_"+tempSubstr[1]).css("overflow-x", "scroll");
                }
                
                addStepInfoTable(tempSubstr[1], jQuery("#subRouteStepNum_"+tempSubstr[1]).val()); // Add a row in the stepInfoTable
            }); // End - Add a circle in the subRouteSteps_n column
            
            // Start - Change the color of the clicked routeCircles, and update the Step Information
            jQuery('.routeCircles').live("click",function() {
                imageId = this.id;
                tempSubstr = imageId.split('_');
                jQuery(".stepInfoDiv").show(); // show the hidden div
                jQuery(".stepInfoRows").hide(); // hide all stepInfoRows
                jQuery("#stepInfo_"+tempSubstr[1]+"_"+tempSubstr[3]).show(); // Hide the step information depending on the clicked circle
                
                // Make the previous clicked RouteCircles to green
                if ( jQuery("#clickedRouteCircle").val() != "" ) {
                    updateCircleColor(jQuery("#clickedRouteCircle").val(), "grn"); 
                }
                
                jQuery("#clickedRouteCircle").val(imageId); // Update the value of clickedRouteCircle
                updateCircleColor(imageId, "ylw"); // Update the clicked route circle
                adjustStepNum(imageId); // Adjust now the step number.
            }); // End - Go back to admRouteSetup.php 
            
            // Start - Add an attachment row depending on the clicked addReqAttachBtn 
            jQuery('.addReqAttachBtn').live("click",function() {
                tempSubstr = this.id.split('_');
                
                // hide the No Required attachment td
                jQuery("#noReqTr_"+tempSubstr[1]+"_"+tempSubstr[2]).hide();
                
                tempString = addAttachmentRow(tempSubstr[1], tempSubstr[2]);
                jQuery("#addReqAttachBtnRw_"+tempSubstr[1]+"_"+tempSubstr[2]).before(tempString);
            }); // End - Add an attachment row depending on the clicked addReqAttach
            
            // Start - Remove an attachment row depending on the clicked rmvReqAttachBtn
            jQuery('.rmvReqAttach').live("click",function() {
                tempSubstr = this.id.split('_');
                jQuery("#reqAttachRow_"+tempSubstr[1]+"_"+tempSubstr[2]+"_"+tempSubstr[3]).remove();
                
                // Add an attachment row if the table row is equal to 2
                if ( jQuery("#reqAttachTable_"+tempSubstr[1]+"_"+tempSubstr[2]+" tr").length == 3 ) {
                    
                    // Show the No Required Attachment Message
                    jQuery("#noReqTr_"+tempSubstr[1]+"_"+tempSubstr[2]).show();
                    
                    // Add new attachment dropdown
//                    tempString = addAttachmentRow(tempSubstr[1], tempSubstr[2]);
//                    jQuery("#addReqAttachBtnRw_"+tempSubstr[1]+"_"+tempSubstr[2]).before(tempString);
                }
            }); // Start - Remove an attachment row depending on the clicked rmvReqAttach
            
            // Start - Add a recipient row depending on the clicked addRecipientBtn
            jQuery('.addRecipientBtn').live("click",function() {
                tempSubstr = this.id.split('_');
                tempString = addRecipientRow(tempSubstr[1], tempSubstr[2]);
                jQuery("#addRecipientBtnRw_"+tempSubstr[1]+"_"+tempSubstr[2]).before(tempString);
            }); // End - Add a recipient row depending on the clicked addRecipientBtn
            
            // Start - Remove a recipient row depending on the clicked rmvRecipient
            jQuery('.rmvRecipient').live("click",function() {
                tempSubstr = this.id.split('_');
                jQuery("#recipientRow_"+tempSubstr[1]+"_"+tempSubstr[2]+"_"+tempSubstr[3]).remove();
                
                // Add a recipient row if the table row is equal to 2
                if ( jQuery("#recipientTable_"+tempSubstr[1]+"_"+tempSubstr[2]+" tr").length == 2 ) {
                    tempString = addRecipientRow(tempSubstr[1], tempSubstr[2]);
                    jQuery("#addRecipientBtnRw_"+tempSubstr[1]+"_"+tempSubstr[2]).before(tempString);
                }
            }); // Start - Remove a recipient row depending on the clicked rmvRecipient
            
            // Start - Remove a step information row depending on the clicked rmvStepInfoRow
            jQuery('.rmvStepInfoRow').live("click",function() {
                tempSubstr = this.id.split('_');
                jQuery("#stepInfo_"+tempSubstr[1]+"_"+tempSubstr[2]).remove();
                jQuery(".stepInfoDiv").hide(); // hide the hidden div
                
                // Remove the line, check if null, for mac computers purpose
                if ( jQuery("#route_"+tempSubstr[1]+"_line_"+tempSubstr[2]).width() != null ) {
                    jQuery("#route_"+tempSubstr[1]+"_line_"+tempSubstr[2]).remove();
                }
                
                jQuery("#route_"+tempSubstr[1]+"_circle_"+tempSubstr[2]).remove(); // Remove the circle
                
                // Count the circles depending on what route number
                flagFirst = true;
                totalCircles = 0;
                tempFirstId = "";
                tempLastId = "";
                
                jQuery('.routeCircle_'+tempSubstr[1]).each(function(index) {
                    totalCircles++;
                    tempLastId = this.id;
                    
                    if ( flagFirst == true ) {
                        tempFirstId = this.id;
                        flagFirst = false;
                    }
                });
                
                if ( totalCircles == 0 ) {
                    // Create new "Single" circle
                    jQuery("#addStep_"+tempSubstr[1]).click();
                }
                else if ( totalCircles == 1 ) {
                    // Make to "Single" circle
                    jQuery("#"+tempLastId).attr("src", "images/trackDoc/version"+circleVersion+"/single/grn_nothov_sngle.png");
                    
                    // Delete also the line if tempLastId will now become the first circle in the route
                    tempSubstr2 = tempLastId.split('_');
                    jQuery("#route_"+tempSubstr2[1]+"_line_"+tempSubstr2[3]).remove();
                }
                else {
                    // Make to "Last" circle
                    jQuery("#"+tempLastId).attr("src", "images/trackDoc/version"+circleVersion+"/last/grn_nothov_last.png");
                    
                    // Delete the first line, if the first circle was removed
                    tempSubstr2 = tempFirstId.split('_');
                    jQuery("#route_"+tempSubstr2[1]+"_line_"+tempSubstr2[3]).remove();
                    
                    // Make to "First" circle
                    jQuery("#"+tempFirstId).attr("src", "images/trackDoc/version"+circleVersion+"/first/grn_nothov_frst.png");
                }
            }); // Start - Remove a step information row depending on the clicked rmvStepInfoRow 
            
            // Start - Adjust the step number in the step information depending on the clicked circle
            function adjustStepNum(circleId) {
                tempSubstr = circleId.split('_');
                subRouteRowTrNum = tempSubstr[1];
                tempRowNum = subRouteRowTrNum;
                stepNum = tempSubstr[3];

                // Set count
                count = 0;
                if ( parseInt(tempRowNum) > 3 ) {
                    // Get the last count of the subRouteRow_1
                    jQuery(".routeCircle_1").each(function(index) {
                        count++;
                    });
                }
                
                // Start - Iterate on the routeCircle_n, depending on the subRouteRow 
                jQuery(".routeCircle_"+subRouteRowTrNum).each(function(index) {
                    count++;

                    if ( circleId == this.id ) {
                        jQuery("#rowStepNum_"+subRouteRowTrNum+"_"+stepNum).html(count);
                        
                        // Get sub route name
                        tempName = getSubRouteName(subRouteRowTrNum);
                        jQuery("#rowSubRouteName_"+subRouteRowTrNum+"_"+stepNum).html(tempName);
                    }
                }); // End - Iterate on the routeCircle_n, depending on the subRouteRow
            } // End - Adjust the step number in the step information depending on the clicked circle
            
            // Start - Get sub route name depending on the passed rowNum
            function getSubRouteName(rowNum) {
                tempName = "";
                
                if ( rowNum == "1" ) {
                    tempName = "Initial Route";
                }
                else {
                    if ( jQuery("#subRouteDrpDwn_"+rowNum).val() != "newSubRoute" && jQuery("#subRouteDrpDwn_"+rowNum).val() != "selectSubRoute" ) {
                        tempName = jQuery("#subRouteDrpDwn_"+rowNum+" :selected").text();
                    }
                    else {
                        if ( jQuery("#subRouteDrpDwn_"+rowNum).val() == "newSubRoute" ) {
                            tempName = jQuery("#subRouteNameIptBx_"+rowNum).val();
                        }
                    }
                }
                
                return tempName;
            } // End - Get sub route name depending on the passed rowNum
            
            // Start - Add a row in the stepInfoTable
            function addStepInfoTable(rowNum, stepNum){
                stepInfoTr = "";
                stepInfoTr += "<tr id='stepInfo_"+rowNum+"_"+stepNum+"' class='stepInfo_"+rowNum+" stepInfoRows' style='display:none;'>";
                stepInfoTr += "<td>";
                stepInfoTr += "<table border='0' style='border-top-style:none;'>";
                
                stepInfoTr += "<tr>"; // Start - tr first row
                
                // *************** Step Number ***************
                stepInfoTr += "<td valign='top'>"; // Start td
                stepInfoTr += "<table border='0' style='border-top-style:none;'>";
                stepInfoTr += "<tr>";
                stepInfoTr += "<td>Step Number : </td>";
                stepInfoTr += "<td><span id='rowStepNum_"+rowNum+"_"+stepNum+"'></span></td>";
                stepInfoTr += "</tr>";
                stepInfoTr += "<tr>";
                stepInfoTr += "<td>Sub Route Name : </td>";
                stepInfoTr += "<td><span id='rowSubRouteName_"+rowNum+"_"+stepNum+"'></span></td>";
                stepInfoTr += "</tr>";
                stepInfoTr += "<tr>";
                stepInfoTr += "<td>Category : </td>";
                stepInfoTr += "<td><input type='text' id='category_"+rowNum+"_"+stepNum+"' class='category_"+rowNum+" category' /></td>";
                stepInfoTr += "</tr>";
                stepInfoTr += "</table>";
                stepInfoTr += "</td>"; // End td
                
                // *************** Role and Transaction cancelled ***************
                stepInfoTr += "<td valign='top'>"; // Start td
                stepInfoTr += "<table border='0' style='border-top-style:none;'>";
                stepInfoTr += "<tr>";
                stepInfoTr += "<td>Recipient Role : </td>";
                stepInfoTr += "<td>";
                stepInfoTr += "<select id='role_"+rowNum+"_"+stepNum+"' class='role_"+rowNum+" recipientRoles'>";
                stepInfoTr += "<option value='1'>Sender</option>";
                stepInfoTr += "<option value='2'>Approving Authority</option>";
                stepInfoTr += "<option value='3'>Archiver</option>";
                stepInfoTr += "</select>";
                stepInfoTr += "</td>";
                stepInfoTr += "</tr>";
                
                stepInfoTr += "<tr>";
                stepInfoTr += "<td>Transaction Can Be Cancelled : </td>";
                stepInfoTr += "<td>";
                stepInfoTr += "<select id='cancel_"+rowNum+"_"+stepNum+"' class='cancel_"+rowNum+" canBeCancelled'>";
                stepInfoTr += "<option value='No'>No</option>";
                stepInfoTr += "<option value='Yes'>Yes</option>";
                stepInfoTr += "</select>";
                stepInfoTr += "</td>";
                stepInfoTr += "</tr>";
                
                stepInfoTr += "<tr>";
                stepInfoTr += "<td valign='top'>User Activity : </td>";
                stepInfoTr += "<td><textarea rows='4' cols='30' id='userAct_"+rowNum+"_"+stepNum+"' class='userAct_"+rowNum+" userActivity'></textarea></td>";
                stepInfoTr += "</tr>";
                stepInfoTr += "</table>";
                stepInfoTr += "</td>"; // End td
                
                stepInfoTr += "</tr>";  // End - tr first row
                
                stepInfoTr += "<tr>"; // Start - tr second row
                
                // *************** Required Attachments ***************
                stepInfoTr += "<td valign='top'>"; // Start td
                stepInfoTr += "<span class='screenlet' style='text-align:center;padding-left : 0; padding-right : 0; padding-top : 0;width:100%' >Required Attachments</span>";
                stepInfoTr += "<table id='reqAttachTable_"+rowNum+"_"+stepNum+"' border='1' style='padding-left : 0; padding-right : 0; padding-top : 0; width:100%'>";
                
                // Required Attachment header
                stepInfoTr += "<tr><th>Attachment Name</th><th>Action</th></tr>";
                stepInfoTr += "<tr id='noReqTr_"+rowNum+"_"+stepNum+"'><td colspan='2'>No Required Attachment</td></tr>";
//                tempString = addAttachmentRow(rowNum, stepNum);
//                stepInfoTr += tempString;
                
                // Row for Add Attachment Button
                stepInfoTr += "<tr id='addReqAttachBtnRw_"+rowNum+"_"+stepNum+"'>";
                stepInfoTr += "<td> &nbsp <input type='hidden' id='addReqAttachNumRow_"+rowNum+"_"+stepNum+"' value='1' /></td>"; // This variable will be used in incrementing the the rows of the reqAttachment
                stepInfoTr += "<td style='text-align:center;'><input type='Submit' id='addReqAttachBtn_"+rowNum+"_"+stepNum+"' value='Add' class='siteGreenButton addReqAttachBtn' /></td>";
                stepInfoTr += "</tr>";
                stepInfoTr += "</table>";
                stepInfoTr += "</td>"; // End td
                
                // *************** Recipient ***************
                stepInfoTr += "<td valign='top'>"; // Start td
                stepInfoTr += "<span class='screenlet' style='text-align:center;padding-left : 0; padding-right : 0; padding-top : 0;width:100%' >Recipients</span>";
                stepInfoTr += "<table id='recipientTable_"+rowNum+"_"+stepNum+"' border='1' style='padding-left : 0; padding-right : 0; padding-top : 0; width:100%'>";
                
                // Required Recipient header
                stepInfoTr += "<tr><th>Position</th><th>Action</th></tr>";
                
                tempString = addRecipientRow(rowNum, stepNum);
                stepInfoTr += tempString;
                
                // Row for Add Recipient Button
                stepInfoTr += "<tr id='addRecipientBtnRw_"+rowNum+"_"+stepNum+"'>";
                stepInfoTr += "<td> &nbsp <input type='hidden' id='addRecipientNumRow_"+rowNum+"_"+stepNum+"' value='1' /></td>"; // This variable will be used in incrementing the the rows of the addRecipientRow
                stepInfoTr += "<td style='text-align:center;'><input type='Submit' id='addRecipientBtn_"+rowNum+"_"+stepNum+"' value='Add' class='siteGreenButton addRecipientBtn' /></td>";
                stepInfoTr += "</tr>";
                stepInfoTr += "</table>";
                stepInfoTr += "</td>"; // End td
                
                stepInfoTr += "</tr>"; // End - tr second row
                
                
                // *************** Remove Step Info Row ***************
                stepInfoTr += "<tr>"; // Start - tr third row
                stepInfoTr += "<td style='text-align: right;' colspan='2'>"; // Start td
                stepInfoTr += "<input type='Submit' id='rmvStepInfoRow_"+rowNum+"_"+stepNum+"' value='Remove' class='siteGreenButton rmvStepInfoRow'>"; // Remove Step Info Row Button
                stepInfoTr += "</td>"; // End td
                stepInfoTr += "</tr>"; // Start - tr third row
                
                stepInfoTr += "</table>";
                stepInfoTr += "</td>";
                stepInfoTr += "</tr>";
                
                jQuery("#stepInfoTable").append(stepInfoTr);
            } // End - Add a row in the stepInfoTable
            
            // Start - Get the Positions, put inside tr, this will be appended later on to recipientTable
            function addRecipientRow(rowNum, stepNum) {
                var tempString = "";
                
                if ( jQuery("#addRecipientNumRow_"+rowNum+"_"+stepNum).val() == undefined ) {
                    addRecipientNumRow = 1;
                }
                else {
                    addRecipientNumRow = jQuery("#addRecipientNumRow_"+rowNum+"_"+stepNum).val(); // Get the value of addRecipientNumRow
                    addRecipientNumRow = parseInt(addRecipientNumRow) + 1; // Change into integer, then increment
                    jQuery("#addRecipientNumRow_"+rowNum+"_"+stepNum).val(addRecipientNumRow); // Set the addRecipientNumRow
                    addRecipientNumRow = jQuery("#addRecipientNumRow_"+rowNum+"_"+stepNum).val(); // Get the incremented value
                }
                
                tempString += "<tr id='recipientRow_"+rowNum+"_"+stepNum+"_"+addRecipientNumRow+"'>";
                tempString += "<td>";
                tempString += "<select id='recipientRow_"+rowNum+"_"+stepNum+"' class='recipientRow_"+rowNum+"_"+stepNum+" recipientRow_"+rowNum+" recipientRow'>";
                
                // Start - Ajax for getting the positions
                jQuery.ajax({
                    type : 'POST',
                    url : 'ajaxRequests/admGetDeptPos.php',
                    dataType : 'json',
                    async : false,
                    data: {
                        departmentId : "All" ,
                        positionId : "All"
                    },
                    success : function(data){
                        jQuery.each(data, function(index, data) {
                            tempString += "<option value='"+data.deptPosId+"'>"+data.departmentName+" - "+data.positionName+ " </option>";
                        });
                    },
                    error : function() {
                        alert("Error : Ajax in getting the positions was not successful.");
                    }
                }); // End - Ajax for getting the positions
                
                tempString += "</select>";
                tempString += "</td>";
                
                // Prepare the delete button
                tempString += "<td style='text-align:center;'><img id='rmvRecipient_"+rowNum+"_"+stepNum+"_"+addRecipientNumRow+"' class='rmvRecipient' src='images/ximage.png' height='20px' width='20px' style='cursor: pointer;'/></td>";
                
                tempString += "</tr>";
                
                return tempString;
            } // End - Get the Positions, put inside tr, this will be appended later on to recipientTable
            
            // Start - Get the Attachment, put inside tr, this will be appended later on to reqAttachTable
            function addAttachmentRow(rowNum, stepNum) {
                var tempString = "";
                
                if ( jQuery("#addReqAttachNumRow_"+rowNum+"_"+stepNum).val() == undefined ) {
                    addReqAttachNumRow = 1;
                }
                else {
                    addReqAttachNumRow = jQuery("#addReqAttachNumRow_"+rowNum+"_"+stepNum).val(); // Get the value of addReqAttachNumRow
                    addReqAttachNumRow = parseInt(addReqAttachNumRow) + 1; // Change into integer, then increment
                    jQuery("#addReqAttachNumRow_"+rowNum+"_"+stepNum).val(addReqAttachNumRow); // Set the addReqAttachNumRow
                    addReqAttachNumRow = jQuery("#addReqAttachNumRow_"+rowNum+"_"+stepNum).val(); // Get the incremented value
                }
                
                tempString += "<tr id='reqAttachRow_"+rowNum+"_"+stepNum+"_"+addReqAttachNumRow+"'>";
                tempString += "<td>";
                tempString += "<select id='reqAttach_"+rowNum+"_"+stepNum+"' class='reqAttach_"+rowNum+"_"+stepNum+" reqAttach_"+rowNum+" reqAttach'>";
                
                // Start - Ajax for getting the attachments
                jQuery.ajax({
                    type : 'POST',
                    url : 'ajaxRequests/getDocumentList.php',
                    dataType : 'json',
                    async : false,
                    data: {
                        docType : "Attachment"
                    },
                    success : function(data){
                        jQuery.each(data, function(index, data) {
                            tempString += "<option value='"+data.documentSetupId+"'>"+data.documentName+"</option>";
                        });
                    },
                    error : function() {
                        alert("Error : Ajax in getting the attachments was not successful.");
                    }
                }); // End - Ajax for getting the attachments
                
                tempString += "</select>";
                tempString += "</td>";
                
                // Prepare the delete button
                tempString += "<td style='text-align:center;'><img id='rmvReqAttach_"+rowNum+"_"+stepNum+"_"+addReqAttachNumRow+"' class='rmvReqAttach' src='images/ximage.png' height='20px' width='20px' style='cursor: pointer;'/></td>";
                
                tempString += "</tr>";
                
                return tempString;
            } // End - Get the Attachment, put inside tr, this will be appended later on to reqAttachTable
            
            // Start - Change the route color depending on the passed parameters
            function updateCircleColor(imageId, theColor) {
                // Get on what place number is the clicked route
                tempSubstr = imageId.split('_');
                idsMeet = false;
                count = 0;
                total = 0;
                jQuery('.routeCircle_'+tempSubstr[1]).each(function(index) {
                    if ( idsMeet == false ) {
                        count++;
                    }

                    total++;
                    tempVar = this.id;
                    
                    if ( imageId == tempVar ) {
                        idsMeet = true;
                    }
                });
                
                // Prepare the variables and update the image
                if ( count == 1 ) {
                    // First
                    
                    if ( total == 1 ) {
                        // Single
                        jQuery("#"+imageId).attr("src", "images/trackDoc/version"+circleVersion+"/single/"+theColor+"_nothov_sngle.png");
                    }
                    else {
                        // First
                        jQuery("#"+imageId).attr("src", "images/trackDoc/version"+circleVersion+"/first/"+theColor+"_nothov_frst.png");
                    }
                }
                else if ( count == total ) {
                    // Last
                    jQuery("#"+imageId).attr("src", "images/trackDoc/version"+circleVersion+"/last/"+theColor+"_nothov_last.png");
                }
                else {
                    // Center
                    jQuery("#"+imageId).attr("src", "images/trackDoc/version"+circleVersion+"/center/"+theColor+"_nothov_cntr.png");
                }
            } // End - Change the route color depending on the passed parameters
            
            // Start - Get the needed picture of the circle
            function getNeededCircle(tempCircleId, rowNum, folderName, theColor, hoverFlag, theSuffix) {
                tempCircle = "<img id='"+tempCircleId+"' class='routeCircle_"+rowNum+" routeCircles' style='cursor:pointer;' width='"+circleWidth+"' height='"+circleHeight+"' src='images/trackDoc/version"+circleVersion+"/"+folderName+"/"+theColor+"_"+hoverFlag+"_"+theSuffix+".png' />";
                return tempCircle;
            } // End - Get the needed picture of the circle
            
            // Start - Get the needed picture of the line
            function getLine(tempLineId, rowNum) {
                tempLine = "<img id='"+tempLineId+"' class='routeLine_"+rowNum+"' src='images/trackDoc/version"+circleVersion+"/line/line_drk_ornge.png' alt='Line' width='"+lineWidth+"' height='"+lineHeight+"'/>";
                return tempLine;
            } // End - Get the needed picture of the line
            
            // Start - Get the sub route ids from the dropdown
            function getSubRouteIds() {
                var subRouteIds = ""; 
                
                jQuery('.subRouteDrpDwn').each(function(index) {
                    tempVar = this.id;
                    tempSubstr = tempVar.split('_');
                    subRouteIds += jQuery('#' + this.id).val() + "_"+tempSubstr[1]+",";
                });
                
                return subRouteIds;
            } // End - Get the sub route ids from the dropdown
            
            // Start -  Get newly created subRouteIds from subRouteIdIptBx
            function getNewSubRouteIds() {
                var newSubRouteIds = "";
                
                jQuery('.subRouteDrpDwn').each(function(index) {
                    tempVar = this.id;
                    tempSubstr = tempVar.split('_');
                    if ( jQuery('#' + this.id).val() == "newSubRoute" ) {
                        newSubRouteIds += jQuery('#subRouteIdIptBx_' + tempSubstr[1]).val() + "_"+tempSubstr[1]+",";
                    }
                });
                
                return newSubRouteIds;
            } // End -  Get newly created subRouteIds from subRouteIdIptBx
            
            // Start - Get the sub route names from the subRouteNameIptBx
            function getNewSubRouteNames() {
                var subRouteNames = ""; 
                
                jQuery('.subRouteDrpDwn').each(function(index) {
                    tempVar = this.id;
                    tempSubstr = tempVar.split('_');
                    if ( jQuery('#' + this.id).val() == "newSubRoute" ) {
                        subRouteNames += jQuery('#subRouteNameIptBx_' + tempSubstr[1]).val() + "_"+tempSubstr[1]+",";
                    }
                });
                
                return subRouteNames;
            } // End - Get the sub route names from the subRouteNameIptBx
            
            // Start - Get the sub route steps of each route
            function getSubRouteSteps(){
                var subRouteSteps = "";
                
                jQuery('.routeCircles').each(function(index) {
                    subRouteSteps += this.id+",";
                });
                
                return subRouteSteps;
            } // End - Get the sub route steps of each route
            
            // Start - Get the dropdown values depending on the passed class
            function getDrpDwnValues(theClass) {
                var arrayString = "";
                
                jQuery('.'+theClass).each(function(index) {
                    tempSubstr = this.id.split('_'); // Get rowNum and stepNum
                    arrayString += jQuery(this).val()+"_"+tempSubstr[1]+"_"+tempSubstr[2]+","; // Append the data
                });
                
                return arrayString;
            } // End - Get the dropdown values depending on the passed class
            
            // Start - Check if there is a duplicate value of subRouteIdIptBx
            function noDupSRIdIptBx() {
                noSame = true;
                
                if ( jQuery('#subRouteTable tr').length <= 4 ) {
                    return noSame;
                }
                else {
                    for( x = 2 ; x <= subRouteNumRows && noSame == true ; x++ ){
                        for( y = 2 ; y <= subRouteNumRows && noSame == true ; y++ ){
                            if ( x != y ) {
                                // If both the selected value of the drop down is "newSubRoute",
                                // then check if they have the same subRouteIdIptBx
                                if ( jQuery("#subRouteDrpDwn_"+x).val() == "newSubRoute" && jQuery("#subRouteDrpDwn_"+y).val() == "newSubRoute" ) {
                                    // Check if they have the same subRouteIdIptBx
                                    if ( jQuery("#subRouteIdIptBx_"+x).val() != "" && jQuery("#subRouteIdIptBx_"+y).val() != "" && jQuery("#subRouteIdIptBx_"+x).val() == jQuery("#subRouteIdIptBx_"+y).val() ) {
                                        noSame = false;
                                    }
                                }
                            } // End - x != y
                        } // inner for loop
                    } // outer for loop
                    
                     return noSame;
                }
            } // End - Check if there is a duplicate value of subRouteIdIptBx
            
            // Start - Check if all of the needed information in creating a new sub route is filled up
            function validNewSubRoute() {
                validVal = true;
                
                if ( jQuery('#subRouteTable tr').length != 3 ) {
                    jQuery('.subRouteDrpDwn').each(function(index) {
                        if ( jQuery("#"+this.id).val() == "newSubRoute" ) {
                            tempSubstr = this.id.split('_');

                            if ( jQuery("#subRouteIdIptBx_"+tempSubstr[1]).val() == "" || jQuery("#subRouteNameIptBx_"+tempSubstr[1]).val() == "" ) {
                                validVal = false;
                            }
                        }
                    });
                }
                
                return validVal;
            } // End - Check if all of the needed information in creating a new sub route is filled up
            
            // Start - Check if there is a subRouteDrpDwn that has a value: selectSubRoute
            function noSelectSubRoute() {
                validVal = true;
                
                if ( jQuery('#subRouteTable tr').length != 3 ) {
                    jQuery('.subRouteDrpDwn').each(function(index) {
                        if ( jQuery("#"+this.id).val() == "selectSubRoute" ) {
                            validVal = false;
                        }
                    });
                }
                
                return validVal;
            } // End - Check if there is a subRouteDrpDwn that has a value: selectSubRoute
            
            // Start - Check subRouteTable if there are any duplicates of subroute
            function noSameSubRoute() {
                noSame = true;
                
                if ( jQuery('#subRouteTable tr').length <= 4 ) {
                    return noSame;
                }
                else {
                    for( x = 2 ; x <= subRouteNumRows && noSame == true ; x++ ){
                        for( y = 2 ; y <= subRouteNumRows && noSame == true ; y++ ){
                            if ( x != y ) {
                                // If one of them has the value of "selectSubRoute", then don't check it anymore
                                if ( jQuery("#subRouteDrpDwn_"+x).val() != "selectSubRoute" && jQuery("#subRouteDrpDwn_"+y).val() != "selectSubRoute" ) {
                                    if ( jQuery("#subRouteDrpDwn_"+x).val() == jQuery("#subRouteDrpDwn_"+y).val() && jQuery("#subRouteDrpDwn_"+x).val() != undefined && jQuery("#subRouteDrpDwn_"+y).val() != undefined  ) {
                                        // If both the selected value of the drop down is "newSubRoute",
                                        // then check if they have the same subRouteIdIptBx
                                        if ( jQuery("#subRouteDrpDwn_"+x).val() == "newSubRoute" && jQuery("#subRouteDrpDwn_"+y).val() == "newSubRoute" ) {
                                            // Check if they have the same subRouteIdIptBx
//                                            if ( jQuery("#subRouteIdIptBx_"+x).val() != "" && jQuery("#subRouteIdIptBx_"+y).val() != "" && jQuery("#subRouteIdIptBx_"+x).val() == jQuery("#subRouteIdIptBx_"+y).val() ) {
//                                                noSame = false;
//                                            }
                                        }
                                        else {
                                            noSame = false;
                                        }
                                    } // If has value of dropdown
                                } // If one of the dropdown doesn't have the value of "selectSubRoute"
                            } // End - x != y
                        } // inner for loop
                    } // outer for loop
                    
                     return noSame;
                }
            } // End - Check subRouteTable if there are any duplicates of subroute
            
            // Start - Add list of Sub Route Name drop down
            function addSubRouteDrpDwn() {
                var tempRow = "";
                
                jQuery.ajax({
                    type : 'POST',
                    url : 'ajaxRequests/admGetSubRoutes.php',
                    dataType : 'json',
                    async : false,
                    data: {
                    },
                    success : function(data){
                        if (data) {
                            tempRow += "<option value='selectSubRoute'>Select Sub Route</option>";
                            jQuery.each(data, function(index, data) {
                                if ( data.subRouteId != "REJECTTRAC" && data.subRouteId != "CANCELTRAC" ) {
                                    tempRow += "<option value='"+data.subRouteId+"'>"+data.subRouteName+"</option>";
                                }
                            });
                            
                            tempRow += "<option value='newSubRoute'>Create New Sub Route</option>";
                        } 
                    },
                    error : function() {
                        alert("Error : Adding sub route name list row was not successful.");
                    }
                });

                return tempRow;
            } // End - Add list of Sub Route Name drop down
            
            // Start - Check if there is same required attachment in each step.
            function noSameReqAttach() {
                noSame = true;
                
                // Start - Iterate each routeCircles
                jQuery(".routeCircles").each(function(index) {
                    tempSubStr = this.id.split('_');
                    rowNum = tempSubStr[1];
                    stepNum = tempSubStr[3];
                    
                    outerCount = 0;
                    // Start - Iterate each outer reqAttach_n
                    jQuery(".reqAttach_"+rowNum+"_"+stepNum).each(function(index) {
                        tempOuterId = this;
                        
                        innerCount = 0;
                        // Start - Iterate each inner reqAttach_n
                        jQuery(".reqAttach_"+rowNum+"_"+stepNum).each(function(index) {
                            tempInnerId = this;
                            
                            if ( outerCount != innerCount ) {
                                if ( jQuery(tempOuterId).val() == jQuery(tempInnerId).val() ) {
                                    noSame = false;
                                    
                                    tempName = getSubRouteName(rowNum); // Get sub route name
                                    tempStepNum = jQuery("#rowStepNum_"+rowNum+"_"+stepNum).html(); // Get step num
                                    globalErrMsg = "Error : There is same required attachment in "+tempName+" route,  step "+tempStepNum+".";
//                                    globalErrMsg = "Error : There is same required attachment in route "+rowNum+" step "+stepNum+". "+tempOuterId.id+" "+tempInnerId.id+"_"+outerCount+" "+innerCount+" ";
                                }
                            }
                            
                            innerCount++;
                        }); // End - Iterate each inner reqAttach_n
                        
                        outerCount++;
                    }); // End - Iterate each outer reqAttach_n
                }); // End - Iterate each routeCircles
                
                return noSame;
            } // End - Check if there is same required attachment in each step.
            
            // Start - Check if there is same recipient in each step.
            function noSameRecipient() {
                noSame = true;
                
                // Start - Iterate each routeCircles
                jQuery(".routeCircles").each(function(index) {
                    tempSubStr = this.id.split('_');
                    rowNum = tempSubStr[1];
                    stepNum = tempSubStr[3];
                    
                    outerCount = 0;
                    // Start - Iterate each outer recipientRow_n
                    jQuery(".recipientRow_"+rowNum+"_"+stepNum).each(function(index) {
                        tempOuterId = this;
                        
                        innerCount = 0;
                        // Start - Iterate each inner recipientRow_n
                        jQuery(".recipientRow_"+rowNum+"_"+stepNum).each(function(index) {
                            tempInnerId = this;
                            
                            if ( outerCount != innerCount ) {
                                if ( jQuery(tempOuterId).val() == jQuery(tempInnerId).val() ) {
                                    noSame = false;
                                    
                                    tempName = getSubRouteName(rowNum); // Get sub route name
                                    tempStepNum = jQuery("#rowStepNum_"+rowNum+"_"+stepNum).html(); // Get step num
                                    globalErrMsg = "Error : There is same recipient in "+tempName+" route,  step "+tempStepNum+".";
                                }
                            }
                            
                            innerCount++;
                        }); // End - Iterate each inner recipientRow_n
                        
                        outerCount++;
                    }); // End - Iterate each outer recipientRow_n
                }); // End - Iterate each routeCircles
                
                return noSame;
            } // End - Check if there is same recipient in each step.
            
            // Start - Check if there is an empty user activity field
            function noEmptyUsrAct() {
                notEmpty = true;
                
                // Start - Iterate each userActivity
                jQuery(".userActivity").each(function(index) {
                    if ( jQuery(this).val() == '' ) {
                        tempSubStr = this.id.split('_');
                        rowNum = tempSubStr[1];
                        stepNum = tempSubStr[2];
                        
                        notEmpty = false;
                        
                        tempName = getSubRouteName(rowNum); // Get sub route name
                        tempStepNum = jQuery("#rowStepNum_"+rowNum+"_"+stepNum).html(); // Get step num
                        globalErrMsg = "Error : Please input a user activity in "+tempName+" route,  step "+tempStepNum+".";
                    }
                }); // End - Iterate each userActivity
                
                return notEmpty;
            } // End - Check if there is an empty user activity field
            
            // Start - Check if there is an empty category field
            function noEmptyCategory() {
                notEmpty = true;
                
                // Start - Iterate each category
                jQuery(".category").each(function(index) {
                    if ( jQuery(this).val() == '' ) {
                        tempSubStr = this.id.split('_');
                        rowNum = tempSubStr[1];
                        stepNum = tempSubStr[2];
                        
                        notEmpty = false;
                        
                        tempName = getSubRouteName(rowNum); // Get sub route name
                        tempStepNum = jQuery("#rowStepNum_"+rowNum+"_"+stepNum).html(); // Get step num
                        globalErrMsg = "Error : Please input a category in "+tempName+" route,  step "+tempStepNum+".";
                    }
                }); // End - Iterate each category
                
                return notEmpty;
            } // End - Check if there is an empty category field
            
            // End - jQueries for Create
            // ************************************************************************************
            
            // ************************************************************************************
            // Start - jQueries for both Edit and Create
            
            // Start - Go back to admRouteSetup.php
            jQuery('#cancelButton').live("click",function() {
                window.location = 'admRouteSetup.php';
            }); // End - Go back to admRouteSetup.php 
            
            // End - jQueries for both Edit and Create
            // ************************************************************************************
        }); // End - jQuery document ready
    </script>
<!-- HEAD END -->

<?php include("siteMiddle.php"); ?>

<div id="content">
<h1>Edit Route</h1>
    <div class="contentbox">       
        <?php
        // Check permission
        $thePermissions = array('ROUTESTP');
        if ( checkPermission( $thePermissions, $userId ) == true ) {
        ?>
            <span class="screenlet" >Route Information</span>
            <table>
                <tr>
                    <td>Route Name : </td>
                    <td>
                        <input type="text" value="<?php echo $routeName; ?>" name="routeName" id="routeName" class="inputbox"/>
                    </td>
                </tr>
                <tr>
                    <td>Main Document : </td>
                    <td>
                        <select id="documentSetupId">
                        <?php
                            $query =
                                "
                                    SELECT documentSetupId, documentName
                                    FROM DocumentSetup
                                    WHERE type='MainDocument'
                                    ORDER BY documentName
                                ";

                            $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
                            
                            while ( $row = mysql_fetch_array($result) )
                                echo "<option value='".$row['documentSetupId']."'>".$row['documentName']."</option>";
                        ?>
                        </select>
                        
                        <!-- The variable updtDocStpId will be used in updating the documentSetupId -->
                        <input type="hidden" id="updtDocStpId" value="<?php echo $documentSetupId; ?>" />
                    </td>
                </tr>
            </table>
            
            <span class="screenlet" >Routes</span>
            <table border="1" id="subRouteTable" width="100%">
                <!-- Display header -->
                <tr>
                    <th width="33%">Sub Route</th>
                    <th>Sub Route Steps</th>
                    <th width="13.2%">Action</th>
                </tr>
                
                <?php
                    // Get the subRoute of the routeId except NULL, REJECTTRAC, and CANCELTRAC
                    $query =
                        "
                            SELECT subRouteId
                            FROM RouteStep
                            WHERE routeId = '$routeId' AND subRouteId != 'REJECTTRAC' AND subRouteId != 'CANCELTRAC' AND subRouteId IS NOT NULL
                            GROUP BY subRouteId
                            ORDER BY stepId
                        ";
                    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
                    
                    // Put in an array all of the subRouteId of the $routeId
                    $theSubRoutes = array("NULL", "REJECTTRAC", "CANCELTRAC");
                    
                    while ( $row = mysql_fetch_array($result) ) {
                        $theSubRoutes[] = $row['subRouteId'];
                    }
                    
                    // Initialize row number
                    $rowNum = 1;
                    
                    // Start - Iterate $theSubRoutes
                    foreach ($theSubRoutes as $theSubRoute) {
                    ?>
                        <tr id="subRouteRow_<?php echo $rowNum; ?>">
                            <td>
                            <?php
                                // Show the name of the subroute 
                            
                                if ( $theSubRoute == "NULL" ) {
                                    echo "Initial Route";
                                }
                                else {
                                    $tempName = getSubRouteName($theSubRoute); // Get the name of the subRouteId
                                    addSubRouteDrpDwnPhp($rowNum, $theSubRoute, $tempName); // Add the sub route drop down
                                    
                                    // Show subroute name
                                    if ( $theSubRoute == "REJECTTRAC" || $theSubRoute == "CANCELTRAC" ) {
                                        echo $tempName;
                                    }
                                }
                            ?>
                            </td>
                            
                            <td id="subRouteSteps_<?php echo $rowNum; ?>">
                                <div class="scrollRouteOuterDiv" id="subRouteStepsOuterDiv_<?php echo $rowNum; ?>">
                                    <div class="scrollRouteInnerDiv" id="subRouteStepsInnerDiv_<?php echo $rowNum; ?>">
                                    <?php
                                        // Get all the number of circles that needed to be created
                                        // by getting the total number of steps for that subRoute
                                        $totalStepNum = getTotalStepNum($theSubRoute, $routeId);
                                        ?>
                                            <!-- Put the total number of circles created -->
                                            <input type="hidden" id="subRouteStepNum_<?php echo $rowNum; ?>" class="subRouteStepNum" value="<?php echo $totalStepNum; ?>"/>
                                        <?php
                                        $stepNum = 1; // Initialize step number
                                        
                                        // Start - Add the circles
                                        for ( ; $stepNum <= $totalStepNum ; $stepNum++ ) {
                                            // Set the $tempFolderName and $tempSuffix for the image
                                            $tempFolderName = "";
                                            $tempSuffix = "";
                                            $lineFlag = false; // Set the line flag, false for not to create, true for create
                                            
                                            if ( $totalStepNum == 1 ) {
                                                // Single
                                                $tempFolderName = "single";
                                                $tempSuffix = "sngle";
                                            }
                                            else if ( $stepNum == 1 ) {
                                                // First
                                                $tempFolderName = "first";
                                                $tempSuffix = "frst";
                                            }
                                            else if ( $totalStepNum == $stepNum ) {
                                                // Last
                                                $tempFolderName = "last";
                                                $tempSuffix = "last";
                                                $lineFlag = true;
                                            }
                                            else {
                                                // Center
                                                $tempFolderName = "center";
                                                $tempSuffix = "cntr";
                                                $lineFlag = true;
                                            }
                                            
                                            // Print line
                                            if( $lineFlag == true ) {
                                                echo "<img id='route_".$rowNum."_line_".$stepNum."' class='routeLine_".$rowNum."' src='images/trackDoc/version".$circleVersion."/line/line_drk_ornge.png' alt='Line' width='".$lineWidth."' height='".$lineHeight."'/>";
                                            }
                                            
                                            // Print circle
                                            echo "<img id='route_".$rowNum."_circle_".$stepNum."' style='cursor:pointer;' class='routeCircle_".$rowNum." routeCircles' width='".$circleWidth."' height='".$circleHeight."' src='images/trackDoc/version".$circleVersion."/".$tempFolderName."/grn_nothov_".$tempSuffix.".png'/>";
                                        } // End - Add the circles
                                    ?></div>
                                </div>
                            </td>
                            
                            <td>
                                <input type="Submit" id="addStep_<?php echo $rowNum; ?>" class="siteGreenButton addStep" value="Add Step"/>
                                <?php
                                // Show delete button
                                if ( $theSubRoute != "NULL" && $theSubRoute != "REJECTTRAC" && $theSubRoute != "CANCELTRAC" ) {
                                    echo "<img src='images/ximage.png' height='20px' width='20px' style='cursor: pointer;' id='rmvSubRouteRow_".$rowNum."' class='rmvSubRouteRow'/>";
                                }
                                ?>
                            </td>
                        </tr>
                    <?php
                        $rowNum++;
                    } // End - Iterate $theSubRoutes
                ?>
                
                <!-- Display Add Sub Route Button -->
                <tr id="addSubRouteRow">
                    <td> &nbsp </td>
                    <td> &nbsp </td>
                    <td><input type="Submit" id="addSubRoute" class="siteGreenButton" value="Add Sub Route"/></td>
                </tr>
            </table>
            
            <!-- This will be used for showing of step information when a routeCircle was clicked -->
            <div class="stepInfoDiv" style="display:none;">
                <span class="screenlet" >Step Information</span>
                <table id="stepInfoTable">
                <?php
                    // Initialize row number
                    $rowNum = 1;
                
                    // Start - Iterate $theSubRoutes
                    foreach ($theSubRoutes as $theSubRoute) {
                        // Get the step information from the RouteStep
                        // Prepare query
                        if ( $theSubRoute == "NULL" ) {
                            $query =
                            "
                                SELECT *
                                FROM RouteStep
                                WHERE subRouteId IS NULL AND routeId = '$routeId'
                            ";
                        }
                        else {
                            $query =
                            "
                                SELECT *
                                FROM RouteStep
                                WHERE subRouteId = '$theSubRoute' AND routeId = '$routeId'
                            ";
                        }

                        $result = mysql_query($query) or die ('Error in query: $result. ' . mysql_error());
                        $stepNum = 1; // Initialize step number
                        
                        // Start - Add the data in stepInfoTable
                        while ( $row = mysql_fetch_array($result) ) {
                            $RSStepId = $row['stepId'];
                            $RSStepNum = $row['stepNumber'];
                            $RSRole = $row['role'];
                            $RSCancelFlag = $row['canBeCancelled'];
                            $RSUserActivity = $row['userActivity'];
                            $RSCategory = $row['category'];
                            
                            addStepInfoTable($rowNum, $stepNum, $RSStepId, $RSStepNum, $RSRole, $RSCancelFlag, $RSUserActivity, $RSCategory);
                            $stepNum++;
                        } // End - Add the data in stepInfoTable
                        
                        $rowNum++;
                    } // End - Iterate $theSubRoutes
                ?>
                </table>
            </div>
            
            <!-- BUTTONS -->
            <div id="plsWaitDiv" style="display: none;">
                <img src='images/others/loading_1.gif' height='15px' width='15px' /> Please wait
            </div>
            
            <div id="otherBtnsDiv">
                <input type="Button" name="editButton" id="editButton" class="siteGreenButton" value="Save"/>
                <input type="Button" name="cancelButton" id="cancelButton" class="siteRedButton" value="Cancel"/>
            </div>
                
            <!-- Hidden variables -->
             <input type="hidden" id="theRouteId" value="<?php echo $routeId; ?>"/>
            <input type="hidden" id="clickedRouteCircle" value=""/>
            <input type="hidden" id="subRouteNumRows" value="<?php echo ($rowNum-1); ?>"/>
            
            <!-- Hidden form to be used when the editing of route was successful -->
            <form id="routeStpMsgForm" name="routeStpMsgForm" action="admRouteSetup.php" method="POST">
                <input type="hidden" name="routeSuccessMessage" id="routeSuccessMessage" value=""/>
            </form>
        <?php
            mysql_free_result($result);
        }
        else {
            echo "<div class='noPermissionMsgBox noPermissionMsg' style='border: 2px solid red'><div id='noPermissionMsgs'>You have no permission to view this page.</div></div>";
        }
        // End checking permission
        ?>
    </div> <!-- contentbox end div -->
    <div style="position:relative; visibility: hidden">end</div>    <!-- extra space for contentbox -->
</div> <!-- content end div -->
<?php
    include ("siteBottom.php"); 
?>

